package com.yunxin.core.infra.persistence.repository.order;

import com.yunxin.core.domain.model.order.OrderUserApply;
import com.yunxin.core.domain.model.order.OrderUserApplyRepository;
import com.yunxin.core.infra.persistence.converter.OrderConverter;
import com.yunxin.core.infra.persistence.entity.order.OrderUserApplyDO;
import com.yunxin.core.infra.persistence.mapper.order.OrderUserApplyExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zero°
 * @since 2023-07-12
 */
@Repository
@RequiredArgsConstructor
public class OrderUserApplyRepositoryImpl implements OrderUserApplyRepository {

    private final OrderUserApplyExtendMapper orderUserApplyExtendMapper;

    private final OrderConverter orderConverter;

    @Override
    public boolean saveOrderUserApply(OrderUserApply orderUserApply) {
        OrderUserApplyDO orderUserApplyDO = orderConverter.formOrderUserApply(orderUserApply);
        int count = orderUserApplyExtendMapper.insertSelective(orderUserApplyDO);
        return count > 0;
    }

    @Override
    public boolean updateOrderUserApply(OrderUserApply orderUserApply) {
        OrderUserApplyDO orderUserApplyDO = orderConverter.formOrderUserApply(orderUserApply);
        int count = orderUserApplyExtendMapper.updateByPrimaryKeySelective(orderUserApplyDO);
        return count > 0;
    }

    @Override
    public OrderUserApply getOrderUserApplyByApplyOrderNo(String applyOrderNo) {
        OrderUserApplyDO orderUserApplyDO =  orderUserApplyExtendMapper.selectOrderUserApplyByApplyOrderNo(applyOrderNo);
        return orderConverter.toOrderUserApply(orderUserApplyDO);
    }

    /**
     * 根据手机号查询订单详情
     *
     * @param phone
     * @return
     */
    @Override
    public OrderUserApply getIdByUserPhone(String phone) {
        return orderUserApplyExtendMapper.getIdByUserPhone(phone);
    }



    @Override
    public OrderUserApply selectOrderUserApplyAllocationByUserCode(String userCode,Long productId) {
        return orderUserApplyExtendMapper.selectOrderUserApplyAllocationByUserCode(userCode,productId);
    }

    @Override
    public List<OrderUserApply> selectOrderUserApplyAllocationByUserCode1(String userCode,Long productId) {
        return orderUserApplyExtendMapper.selectOrderUserApplyAllocationByUserCode1(userCode,productId);
    }

}
